//
//  PainterTextKLineGameMatrix.m
//  p4
//
//  Created by CaoJun on 15/11/9.
//  Copyright © 2015年 com.baidao. All rights reserved.
//

#import "PainterTextKLineGameMatrix.h"
#include "GameMatrix.h"

using namespace std;
using namespace ytx;

@implementation PainterTextKLineGameMatrix

- (void) drawTopSideText:(CGRect)cgrect withContext:(ChartCanvas *) ctx withViewModelIndexPosition:(ytx::ViewModelIndexPosition *) indexPosition withDataIndex:(int) index withLeftSideTextRect:(CGRect) leftSideTextRect
{
    KLineData * data = (KLineData *)indexPosition->getData();
    
    if (data->indexData.size() == 0){
        return;
    }
    
    YTXConfig * config = YTXConfig::getInstance();
    ytx::Style style = config->style;
    Rectangle & rect = indexPosition->getRectangle();
    
    CGFloat x = rect.getRectWidth();
    
    NSMutableArray * texts = [NSMutableArray new];
    NSMutableArray * fonts = [NSMutableArray new];
    NSMutableArray * colors = [NSMutableArray new];
    NSMutableArray * sizes = [NSMutableArray new];
    
    NSString * font = [ NSString stringWithUTF8String:style.font.c_str() ];
    
    GameMatrixType::GameMatrixType type = (GameMatrixType::GameMatrixType)data->indexData[0][index];
    string bound1 = Tools::Convert2FixString(data->lineData[0][index], data->toFix);
    string bound2 = Tools::Convert2FixString(data->lineData[1][index], data->toFix);
    
    string bound1str = "";
    string bound2str = "";
    
    if (type == GameMatrixType::Long) {
        bound1str = "建议 保守止损:"+bound1;
        bound2str = " 激进止损:"+bound2;
    }
    else if(type == GameMatrixType::Short)
    {
        bound1str = "建议 保守止损"+bound2;
        bound2str = " 激进止损:"+bound1;
    }
    
    if (bound1str != "") {
        [texts addObject: [NSString stringWithUTF8String:bound1str.c_str()] ];
        [colors addObject:[NSString stringWithUTF8String:style.GameMatrixTopTextColor.c_str()]];
        [fonts addObject:font];
        [sizes addObject:@(style.size)];
        
        [texts addObject: [NSString stringWithUTF8String:bound2str.c_str()] ];
        [colors addObject:[NSString stringWithUTF8String:style.GameMatrixTopTextColor.c_str()]];
        [fonts addObject:font];
        [sizes addObject:@(style.size)];
        
        [ctx fillTexts:texts withX:x withY:rect.getBeginY() withColors:colors withFonts:fonts withSizes:sizes withAnchor:RightTop];
    }
}

@end
